#include "gestureutils.h"

using namespace cv;
using namespace std;
using namespace mlgesture;

QImage GestureUtils::convertMat2QImage(const Mat &img) throw (HandGestureException) {
	QImage qimg;
	Mat img_temp;
	switch(img.type()) {
	case CV_8UC3:
		qimg= QImage((const unsigned char*)(img.data), img.cols, img.rows, img.step, QImage::Format_RGB888).rgbSwapped();
		break;
	case CV_8UC1:
		cvtColor(img, img_temp, CV_GRAY2BGR);
		qimg= QImage((const unsigned char*)(img_temp.data), img_temp.cols, img_temp.rows, img_temp.step, QImage::Format_RGB888).rgbSwapped();
		break;
	default:
		throw HandGestureException("Unsupported mat format");
		break;
	}

	return qimg;
}
